package com.ruoyi.web.controller.ToolController;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.web.controller.common.UrlCommon;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Api(tags = "实用工具")
@Controller
@ResponseBody
@RequestMapping("/tool/utility")
public class UtilityController {

    @GetMapping("/cnmoney")
    @ApiOperation("金额转大写")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "money", value = "金额阿拉伯数字")
    })
    public R videoRemoveWatermark(@RequestParam String money) {
        String path = "?money=" + money;
        String s = HttpUtil.get(UrlCommon.DM_CNMONEY + path);
        if (UrlCommon.isCode(s)) {
            Object o = JSONObject.parseObject(JSONObject.parseObject(s).get("data").toString()).get("cnresult");
            return R.ok(o.toString());
        } else {
            return R.fail("转换失败!");
        }
    }

    @GetMapping("/oilprice")
    @ApiOperation("油价查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "prov", value = "省份")
    })
    public R oilprice(@RequestParam String prov) {
        String path = "?prov=" + prov;
        String s = HttpUtil.get(UrlCommon.DM_OILPRICE + path);
        if (UrlCommon.isCode(s)) {
            Object o = JSONObject.parseObject(JSONObject.parseObject(s).get("data").toString());
            return R.ok(o.toString());
        } else {
            return R.fail("查询失败!");
        }
    }

    @GetMapping("/guishu")
    @ApiOperation("号码归属地查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone", value = "号码")
    })
    public R guishu(@RequestParam String phone) {
        String path = "?phone=" + phone;
        String s = HttpUtil.get(UrlCommon.GUI_SHU + path);
        if (UrlCommon.isCode(s)) {
            Object o = JSONObject.parseObject(JSONObject.parseObject(s).get("data").toString());
            return R.ok(o.toString());
        } else {
            return R.fail("查询失败!");
        }
    }

    @GetMapping("/zishu")
    @ApiOperation("文本字数返回")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "msg", value = "文字")
    })
    public R zishu(@RequestParam String msg) {
        String path = "?msg=" + msg;
        return R.ok(HttpUtil.get(UrlCommon.ZI_SHU + path));
    }

    @GetMapping("/car/number/fl")
    @ApiOperation("车牌归属地查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "num", value = "文字"),
    })
    /**
     * 接口  https://api.aa1.cn/doc/car-number-fl.html
     返回结果
     {
     code string	状态码
     province_name	string	省份
     city	string	城市
     organization	string	组织单位
     type	string	10民用20军用30使馆40民航50武警
     }
     **/
    public R carNumberFl(@RequestParam String num) {
        String path = "?num=" + num;
        return R.ok(HttpUtil.get(UrlCommon.CAR_NUMBER_FL + path));
    }

    @GetMapping("/sfz")
    @ApiOperation("身份证校验")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sfz", value = "身份证号码")
    })
    //接口地址 https://api.aa1.cn/doc/sfz.html
    public R sfz(@RequestParam String sfz) {
        String path = "?sfz=" + sfz;
        return R.ok(HttpUtil.get(UrlCommon.SFZ + path));
    }


    @GetMapping("/calculation")
    @ApiOperation("年龄计算生肖星座")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "birthday", value = "出生年月")
    })
    //接口地址 https://api.aa1.cn/doc/Age-calculation.html
    public R calculation(@RequestParam String birthday) {
        String path = "?birthday=" + birthday;
        return R.ok(HttpUtil.get(UrlCommon.CALCULATION + path));
    }

    @GetMapping("/qrcode")
    @ApiOperation("生成二维码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "text", value = "内容"),
            @ApiImplicitParam(name = "size", value = "二维码大小")
    })
    //接口地址 https://api.aa1.cn/doc/Age-calculation.html
    public R qrcode(@RequestParam String text,@RequestParam Integer size) {
        String path = "?frame=1&e=L&text=" + text+"&size=" + size;
        return R.ok(HttpUtil.get(UrlCommon.QRCODE + path));
    }

    @GetMapping("/invoiceInfo")
    @ApiOperation("公司发票信息查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "companyName", value = "公司名称")
    })
    //接口地址 https://api.aa1.cn/doc/invoiceInfo.html
    public R invoiceInfo(@RequestParam String companyName) {
        String path = "?companyName=" + companyName;
        JSONObject jsonObject = JSONObject.parseObject(HttpUtil.get(UrlCommon.INVOICE_INFO + path));
        Object o = jsonObject.get("data");
        return R.ok(o.toString());
    }

}
